<template>
    <!--  导航页  -->
    <div class="index">
        <el-row>
            <el-button type="primary" @click="toCommit">获取提交数据</el-button>
            <el-button type="primary" @click="toCommitter">获取各组提交者数据</el-button>
            <el-button type="primary" @click="toRepoInfo">获取仓库创建时间和最后创建PR时间</el-button>
        </el-row>
        <el-row style="margin: 10px 0">
            <el-button type="primary" @click="toCommitterFromPR">从PR获取commit</el-button>
            <el-button type="primary" @click="toIssuesFromORG">从组织获取issues</el-button>

        </el-row>
    </div>
</template>

<script >

export default {
    name: "index",
    data() {
        return {

        }
    },
    mounted() {
        this.axios.interceptors.response.use(
            response => {
                // 如果返回的状态码为200，说明接口请求成功，可以正常拿到数据
                // 否则的话抛出错误
                if (response && response.status === 200) {
                    return Promise.resolve(response);
                } else {
                    return Promise.reject(response);
                }
            },

            error => {
                if (error && error.config.headers.isRelease){
                    console.warn("错误请求不拦截：" + error.config.url)
                    return
                }
                let msg = ''
                if (error && error.status && error.response.status) {
                    msg = error.response.status
                }
                this.$message.error('请求出错，点击F12进入控制台查看详情：' + msg)
                console.error(error)
                Promise.reject(error);
            }
        );
        if (true){
            return;
        }
        this.axios.get('https://gitee.com/api/v5/repos/OpenHarmony-TPC/okio/pulls/16/commits?access_token=58409b5c205a44f3d99dc1b8e5f41ecd',{
            headers: {
                "Accept": "application/vnd.github.v3+json",
                "Authorization": "token " + "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",
                "isRelease":true
            }
        })
            .then(response => {
                console.log(response);
                let arr = []
                console.log(arr);
            })
            .catch(error => {
                console.log(error);
            });

        const confirmText = [
            '1.本脚本上传文件仅上传至浏览器，不外传至服务器，为避免违规也可断网上传或外网访问',
            '　',
            '2.同时间段内数据存在存在出入，可能是gitee服务器不稳定导致，可先自行排查数据确认是否包含异常数据',
        ]
        const msg = []
        const h = this.$createElement
        for (const i in confirmText) {
            msg.push(h('p', null, confirmText[i]))
        }
        this.$confirm(
            '提示',
            {
                title: '提示',
                message: h('div', null, msg),
                showCancelButton: true,
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'info'
            }
        )
    },
    methods: {
        toCommit() {
            this.$router.push("/Commit");
        },
        toCommitter() {
            this.$router.push("/Committer");
        },
        toRepoInfo() {
            this.$router.push("/RepoInfo");
        },
        toCommitterFromPR() {
            this.$router.push("/CommitterFromPR");
        },
        toIssuesFromORG() {
            this.$router.push("/Issues");
        }
    }
}
</script>

<style scoped>

</style>
